/*
 * Copyright 2025 The JA-SIG Collaborative. All rights reserved.
 * distributed with this file and available online at
 */
package com.lap.auth.adapter.driving.persistence.api.repository;

import com.lap.auth.adapter.driving.persistence.api.ApiViewLogConverter;
import com.lap.auth.adapter.driving.persistence.api.mapper.ApiViewLogMapper;
import com.lap.auth.adapter.driving.persistence.api.po.ApiViewLogPo;
import com.lap.auth.domain.api.ApiViewLog;
import com.lap.auth.domain.api.repository.ApiViewLogRepository;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

@RequiredArgsConstructor
@Repository
public class ApiViewLogRepositoryImpl implements ApiViewLogRepository {

  private final ApiViewLogConverter apiViewLogConverter;
  private final ApiViewLogMapper apiViewLogMapper;

  @Override
  public Integer save(ApiViewLog apiViewLog) {
    ApiViewLogPo apiViewLogPo = apiViewLogConverter.toPo(apiViewLog);
    apiViewLogMapper.insert(apiViewLogPo);
    return apiViewLogPo.getId();
  }

  @Override
  public int deleteById(Integer id) {
    return apiViewLogMapper.deleteByPrimaryKey(id);
  }

  @Override
  public Optional<ApiViewLog> findById(Integer id) {
    var apiViewLogPo = apiViewLogMapper.selectByPrimaryKey(id);
    return Optional.ofNullable(apiViewLogConverter.toDomain(apiViewLogPo));
  }
}
